﻿using SBlogCore.Common.Utilities.Extension;
using SBlogCore.WebAdminApplication.SysOrgManager.Dto;
using SBlogCore.WebAdminApplication.SysOrgManager.IServices;

namespace SBlogCore.WebAdminApplication.SysOrgManager.Controllers
{
    //[Authorize("Admin2")]
    public class SysOrgInfoController: AuthorizeBaseController
    {
        private readonly ISysOrgInfoService _sysOrgInfoService;

        public SysOrgInfoController(ISysOrgInfoService sysOrgInfoService)
        {
            this._sysOrgInfoService = sysOrgInfoService;
        }
        /// <summary>
        /// 获取组织树
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysOrgInfoOutPut>> GetSysOrgList()
        {
            var res=  await _sysOrgInfoService.GetSysOrgList();
            return res.Adapt<List<SysOrgInfoOutPut>>();
        }
        /// <summary>
        /// 获取选项组织树
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SysOrgInfoOption>> GetSysOrgOptions()
        {
            var res = await _sysOrgInfoService.GetSysOrgList();
            return res.Adapt<List<SysOrgInfoOption>>();
        }

        /// <summary>
        /// 创建组织
        /// </summary>
        /// <param name="inPut"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task CreateSysOrgInfo(SysOrgInfoInPut inPut)
        {
            await _sysOrgInfoService.AddSysOrgInfo(inPut);
        }
        [HttpGet]
        public async Task<bool> AnyCode(string value, long? id = null)
        {
            return await _sysOrgInfoService.AnyCode(value, id);
        }

        /// <summary>
        /// 修改组织
        /// </summary>
        /// <param name="inPut"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task UpdateSysOrgInfo(SysOrgInfoEditInPut inPut)
        {
            await _sysOrgInfoService.UpdateSysOrgInfo(inPut);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DeleteSysOrgInfo(List<long> ids)
        {
            return await _sysOrgInfoService.DeleteSysOrgInfo(ids);
        }
    }
}
